'use strict';
var cmsControllers = angular.module('cmsControllers');

cmsControllers
    .controller('CmsVideoCtrl', ['$rootScope', '$scope', '$routeParams',
        'Subscription', 'VideoOpt', 'Video', function ($rootScope, $scope, $routeParams, Subscription, VideoOpt, Video) {

            $scope.showVideoList = function() {
                $scope.videoContent = 'views/component/video/video-list.html';
                var json = VideoOpt.find({action: 'bySubId', subId: $rootScope.CurrentSub.id},function() {
                    $scope.videos = json.data.videos;
                });
            }
            $scope.showVideoList();

            $scope.createVideo = function() {
                $scope.videoContent = 'views/component/video/video-edit.html';
                $scope.video = new Video({subId: $rootScope.CurrentSub.id});
            };
            $scope.editVideo = function(video) {
                $scope.videoContent = 'views/component/video/video-edit.html';
                $scope.video =video;
            };
            $scope.saveVideo = function() {
                new Video($scope.video).$save().then(function() {
                    $scope.showVideoList();
                });
            };
            $scope.deleteVideo = function(video) {
                new Video(video).$delete().then(function() {
                    $scope.showVideoList();
                });
            };
        }]);